<?php

class CaiJiaGeController extends Zend_Controller_Action
{

    public function init()
    {
        $this->view->headScript()->appendFile($this->view->baseUrl().'/js/jquery-1.8.1.min.js');
        //设置引用css
        $this->view->headLink()->appendStylesheet($this->view->baseUrl().'/css/caijiage.css');
        //设置title
        $this->view->headTitle("考眼力-猜价格");
    }

    public function indexAction()
    {
        // action body
        $dbCaiJiaGe=new Application_Model_DbTable_CaiJiaGe();
        $res=$dbCaiJiaGe->getDataByIds('9,23,31,48,56,73,84');
        $this->view->res=$res;
    }
    
    public function pageAction(){
        $id=$this->getRequest()->getParam('id');
        $dbCaiJiaGe=new Application_Model_DbTable_CaiJiaGe();
        $res=$dbCaiJiaGe->getDataById($id);
        $this->view->res=$res;
        
        
        $this->view->sideBar=1;
        //边栏热门文章列表
        $articleModel=new Application_Model_DbTable_Article();
        $this->view->hotArticles=$articleModel->getHotArticle(15);
        //边栏热门商品列表
        $itemsModel=new Application_Model_DbTable_TaobaoItems();
        $this->view->hotItems=$itemsModel->getSidebarHotItems();
    }

    public function listAction(){
        $config=new Zend_Config_Ini(APPLICATION_PATH."/configs/application.ini",'production');
		$db = Zend_Db::factory($config->resources->db);
		$selecter=$db->select()->from('txy_cai_jiage');
		$adapter = new Zend_Paginator_Adapter_DbSelect($selecter);
		$paginator = new Zend_Paginator($adapter);
		$paginator->setItemCountPerPage(8);
		$paginator->setCurrentPageNumber($this->_getParam('page'));
		$this->view->paginator = $paginator;
        
    }

    public function ajaxInputPriceAction(){
        $id=(int)$this->getRequest()->getParam('id');
        $price=(int)$this->getRequest()->getParam('price');
        $ipAddres=$this->getRequest()->getServer('REMOTE_ADDR');
        $date=date('Y-m-d');
        if(0<$price and 9999999>$price){
            $dbCaiJiaGe=new Application_Model_DbTable_CaiJiaGe();
            $res=$dbCaiJiaGe->getDataById($id);
            if(isset($res)){
                $data['cai_id']=$id;
                $data['ip']=$ipAddres;
                $data['price']=$price;
                $data['date']=$date;
                $dbCaiUserPrice=new Application_Model_DbTable_CaiUserPrice();
                $dbCaiUserPrice->addNew($data);
            }
            
        }
        
    }

}

